const ora = require('ora');
const Inquirer = require('Inquirer');
/**
 * @description: 封装loading
 * @param {loading的提示信息,loading中的待执行的函数}
 * @return {函数执行之后的数据}
 */
const waitLoading =
  (msg, fn) =>
  async (...args) => {
    const loading = ora(msg);
    loading.start();
    const data = await fn(...args);
    loading.succeed();
    return data;
  };

/**
 * @description: 设置选择的条件
 * @param {传入的配置对象}
 * @return {选中的选项}
 */
const setChoices = async paramObj => {
  const { name } = paramObj;
  const resultObj = await Inquirer.prompt(paramObj);
  return resultObj[name];
};
module.exports = {
  waitLoading,
  setChoices,
};
